///////////////////////////////////////////////////////////////////////////////////////
//
//	DoD Methamphetamine
//		- Version 1.0
//		- 06.12.2007
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
//	- Allows you to inject yourself or other players with methamphetamines
//
//	- Methamphetamine can be set to do the following:
//		* increase health
//		* give temporary unlimited stamina
//		* lower clients gravity (therefor increasing jump height)
//
//	- Receive kills for injecting fellow team mates
//	- Lose kills for injecting enemy players
//	- Seperate loadouts for each class
//
//	- Psychostats compatible log messages
//
//////////////////////////////////////////////////////////////////////////////////
//
// Commands:
//
//	meth_menu	//shows menu where you can select:
//				//1) Inject yourself
//				//2) Inject another player
//				//3) Count your syringes
//				//0) Exit Menu
//
//	meth_self	//give yourself a shot of methamphetamine
//
//	meth_player	//give another player a methamphetamine shot, stand
//			//close and aim at them while executing the command.
//
//////////////////////////////////////////////////////////////////////////////////
//
// CVARs:
//
//	dod_meth "1"			//Turn on(1)/off(0)
//
//	dod_meth_self "1"		//Allow clients to give themselves methamphetamine shots
//	dod_meth_others "1"		//Allow clients to give other players methamphetamine shots
//
//	dod_meth_allies "1"		//Allow allies to use methamphetamine
//	dod_meth_brits "1"		//Allow british to use methamphetamine
//	dod_meth_axis "1"		//Allow axis to use methamphetamine
//
//	dod_meth_delay_effect "3.0"	//how long it takes for the effects to start (in seconds)
//	dod_meth_delay_inject "2.0"	//how long you must wait to give another injection (in seconds)
//
//	dod_meth_health	"1"		//Turn ON(1)/OFF(0) gaining/losing health
//	dod_meth_health_amt "25"	//Amount of health replenished for each shot
//	dod_meth_health_max "100"	//Max health that methamphetamine will replenish
//
//	dod_meth_stamina "1"		//Turn ON(1)/OFF(0) unlimited stamina effect
//	dod_meth_stamina_time "15.0"	//How long unlimited stamina effect lasts (in seconds)
//
//	dod_meth_gravity "1"		//Turn ON(1)/OFF(0) decreased gravity effect
//	dod_meth_gravity_amt "100.0"	//Amount to decrease client's gravity 
//	dod_meth_gravity_time "20.0"	//How long the gravity effect lasts (in seconds)
//	
//	dod_meth_visual "1"		//Turn ON(1)/OFF(0) visual effect
//	dod_meth_visual_time "20.0"	//How long the visual effect lasts (in seconds)
//	
//	dod_meth_kills_self", "0"	//Amount of kills to get for injecting yourself
//	dod_meth_kills_team", "2"	//Amount of kilsl to get for injecting a teammate
//	dod_meth_kills_enemy", "-5"	//Amount of kills to get for injecting an enemy player
//	
//	dod_meth_msg_spawn", "0"	//Turn ON(1)/OFF(0) spawn chat message
//	dod_meth_msg_use", "1"		//Turn ON(1)/OFF(0) chat message after giving an injection (shows syringes remaining)
//
//	//Number of methamphetamine syringes each class spawns with:
//	dod_meth_garand "1"
//	dod_meth_carbine "0"
//	dod_meth_thompson "1"
//	dod_meth_grease "0"
//	dod_meth_sniper "0"
//	dod_meth_bar "0"
//	dod_meth_30cal "0"
//	dod_meth_bazooka "1"
//	dod_meth_kar "1"
//	dod_meth_k43 "0"
//	dod_meth_mp40 "1"
//	dod_meth_mp44 "0"
//	dod_meth_scharfschutze "0"
//	dod_meth_fg42 "0"
//	dod_meth_scoped_fg42 "0"
//	dod_meth_mg34 "0"
//	dod_meth_mg42 "0"
//	dod_meth_panzerjager "1"
//	dod_meth_enfield "1"
//	dod_meth_sten "0"
//	dod_meth_marksman "0"
//	dod_meth_bren "0"
//	dod_meth_piat "1"
//
//////////////////////////////////////////////////////////////////////////////////
//
// Extra:
//
//	- The SUBTRACT_HP define enables/disables subtracting HP instead of adding
//
//	- The USE_SCIVOICES define enables/disables the extra scientist voice sounds
//		* When you start feeling the methamphetamines you will say:
//			"i seem to be wounded, but i can keep going"
//		* When you inject another player, you will say one of these:
//			"this should make you feel better"
//			"i seem to be wounded, but i can keep going"
//
//	- The FULL_PRECACHE define controls whether all files are precached or not 
//		* If you find that some sounds dont work, enable this
//		* If you get 'file not precached' errors, enable this
//
//////////////////////////////////////////////////////////////////////////////////
//
// Change Log:
//
//	- 06.12.07 - Version 1.0
//		Initial Release
//
///////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////
// Module Include
//
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <dodfun>
#include <dodx>
#include <fun>

///////////////////////////////////////////////////////////////////////////////////////
// Version Control
//
#define VERSION "1.0"

/////////////////////////////////////////////////
// Subtract Health Mode (1=ON/0=OFF)
//
// When this is enabled, health will be
// subtracted instead of added to a player
// after being injected
//
#define SUBTRACT_HP	0

/////////////////////////////////////////////////
// Scientist Voice Sounds (1=ON/0=OFF)
//
// When this is enabled, 3 of the scientist
// voice sounds from half-life will be used.
// One when the amphetamines start to effect
// the player, and 2 different ones when you
// inject a player with amphetamines...
//
#define USE_SCIVOICES	0

/////////////////////////////////////////////////
// FULL PRECACHE   (1=ON/0=OFF)
//
// Enable this if you find that some of
// the sounds dont play or they return
// precache errors.
// 
#define FULL_PRECACHE 0

/////////////////////////////////////////////////
// Debug Mode (1=ON/0=OFF)
//
// this enables the "debug_givemeth" command
// which will give you +5 methamphetamine syringes
// really useful for me when making changes.
//
#define DEBUG_MODE	1

///////////////////////////////////////////////////////////////////////////////////////
// Task IDs
//
#define EFFECT_TASK 	31198
#define NEEDLE_TASK 	77634
#define STAMINA_TASK 	50314
#define GRAVITY_TASK 	45752
#define VISUAL_TASK 	66294
#define VISUALLOOP_TASK 58017

///////////////////////////////////////////////////////////////////////////////////////
// Global Variables
//
new gMsgScreenFade, gMsgScreenShake, gMsgFrags	//, gMsgSetFOV
new playerMethCount[33]
new bool:meth_stamina[33]
new bool:meth_gravity[33]
new bool:meth_visual[33]
new bool:g_round_restart = false
new Float:gravity_default
new Float:g_nextInject[33] = { 0.0, ... }

///////////////////////////////////////////////////////////////////////////////////////
// PCVARs
//
new p_meth, p_delay, p_delayinject, p_health, p_health_amt, p_allies, p_brits, p_axis
new p_self, p_others, p_kills_self, p_kills_team, p_kills_enemy, p_stamina, p_stamina_time
new p_gravity, p_gravity_amt, p_gravity_time, p_visual, p_visual_time
new p_garand, p_carbine, p_thompson, p_grease, p_sniper, p_bar, p_30cal, p_bazooka
new p_kar, p_k43, p_mp40, p_mp44, p_scopedk98, p_fg42, p_scopedfg42, p_mg34, p_mg42, p_panzer
new p_enfield, p_sten, p_marksman, p_bren, p_piat
new p_msg_spawn, p_msg_use

#if SUBTRACT_HP == 0

new p_health_max

#endif

///////////////////////////////////////////////////////////////////////////////////////
// Files
//
new fileNames[5][] =
{
	"models/med_crategibs.mdl",
	"object/object_dropped.wav",
	"player/sprintgrunts.wav",
	"weapons/rifleselect.wav",
	"player/stopbleed.wav"
}

enum
{
	mdl_medical,
	wav_drop,
	wav_grunt,
	wav_inject,
	wav_inject2
}

#if USE_SCIVOICES == 1

new sciVoices[3][] =
{
	"scientist/iwounded.wav",
	"scientist/heal4.wav",
	"scientist/heal2.wav"
	
}

enum
{
	sci_feel,
	sci_inject1,
	sci_inject2
}

#endif

///////////////////////////////////////////////////////////////////////////////////////
//
// Plugin Init
//
public plugin_init()
{
	register_plugin("DoD Methamphetamine", VERSION, "AMXX DoD Team")
	
	register_cvar("dod_methamphetamine_stats", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
	
	//RoundState Event
	register_event("RoundState", "round_message", "a", "1=1", "1=3", "1=4", "1=5")
	
	//Forwards
	//register_statsfwd(XMF_DEATH)
	
	//client spawn
	register_event("ResetHUD", "player_spawn", "be")	
	register_clcmd("fullupdate", "clcmd_fullupdate")	//blocks fullupdate cmd
	
	//Message ID Globals
	gMsgScreenFade = get_user_msgid("ScreenFade")
	gMsgScreenShake = get_user_msgid("ScreenShake")
	gMsgFrags = get_user_msgid("Frags")
	//gMsgSetFOV = get_user_msgid("SetFOV")
	
	//Menu
	register_menu("methamphetamine_menu",(1<<0)|(1<<1)|(1<<2)|(1<<9),"menu_choice")
	
	//Client Commands
	register_clcmd("meth_menu", "meth_menu", 0, "- Opens methamphetamine menu") 
	register_clcmd("meth_self", "meth_self", 0, "- Give yourself a methamphetamine shot")
	register_clcmd("meth_player", "meth_player", 0, "- Give another player a methamphetamine shot")

	//CVARs
	p_meth = register_cvar("dod_meth", "1")
	
	p_self = register_cvar("dod_meth_self", "1")
	p_others = register_cvar("dod_meth_others", "1")
	
	p_allies = register_cvar("dod_meth_allies", "1")
	p_brits = register_cvar("dod_meth_brits", "1")
	p_axis = register_cvar("dod_meth_axis", "1")
	
	p_delay = register_cvar("dod_meth_delay_effect", "3.0")
	p_delayinject = register_cvar("dod_meth_delay_inject", "2.0")
	
	p_health = register_cvar("dod_meth_health","1")
	p_health_amt = register_cvar("dod_meth_health_amt", "25")

#if SUBTRACT_HP == 0
	
	p_health_max = register_cvar("dod_meth_health_max", "100")
	
#endif
	
	p_stamina = register_cvar("dod_meth_stamina", "1")
	p_stamina_time = register_cvar("dod_meth_stamina_time", "20.0")
	
	p_gravity = register_cvar("dod_meth_gravity", "1")
	p_gravity_amt = register_cvar("dod_meth_gravity_amt", "120.0")
	p_gravity_time = register_cvar("dod_meth_gravity_time", "15.0")
	
	p_visual = register_cvar("dod_meth_visual", "1")
	p_visual_time = register_cvar("dod_meth_visual_time", "20.0")
	
	p_kills_self = register_cvar("dod_meth_kills_self", "0")
	p_kills_team = register_cvar("dod_meth_kills_team", "2")
	p_kills_enemy = register_cvar("dod_meth_kills_enemy", "-5")
	
	p_msg_spawn = register_cvar("dod_meth_msg_spawn", "0")
	p_msg_use = register_cvar("dod_meth_msg_use", "1")
	
	p_garand = register_cvar("dod_meth_garand", "1")
	p_carbine = register_cvar("dod_meth_carbine", "1")
	p_thompson = register_cvar("dod_meth_thompson", "1")
	p_grease = register_cvar("dod_meth_grease", "1")
	p_sniper = register_cvar("dod_meth_sniper", "0")
	p_bar = register_cvar("dod_meth_bar", "0") 
	p_30cal = register_cvar("dod_meth_30cal", "0")
	p_bazooka = register_cvar("dod_meth_bazooka", "1")
	p_kar = register_cvar("dod_meth_kar", "1")
	p_k43 = register_cvar("dod_meth_k43", "1")
	p_mp40 = register_cvar("dod_meth_mp40", "1")
	p_mp44 = register_cvar("dod_meth_mp44", "0")
	p_scopedk98 = register_cvar("dod_meth_scharfschutze", "0")
	p_fg42 = register_cvar("dod_meth_fg42", "0")
	p_scopedfg42 = register_cvar("dod_meth_scoped_fg42", "0")
	p_mg34 = register_cvar("dod_meth_mg34", "0")
	p_mg42 = register_cvar("dod_meth_mg42", "0")
	p_panzer = register_cvar("dod_meth_panzerjager", "1")
	p_enfield = register_cvar("dod_meth_enfield", "1")
	p_sten = register_cvar("dod_meth_sten", "1")
	p_marksman = register_cvar("dod_meth_marksman", "0")
	p_bren = register_cvar("dod_meth_bren", "0")
	p_piat = register_cvar("dod_meth_piat", "1")
	
	
#if DEBUG_MODE == 1

	//debug command (gives you +5 methamphetamine syringes)
	register_concmd("debug_givemeth","debug_givemeth",ADMIN_IMMUNITY,"Add 5 methamphetamine syringes to your total count")

#endif
	
}

///////////////////////////////////////////////////////////////////////////////////////
//
// File Precache
//
public plugin_precache() 
{
	precache_model(fileNames[mdl_medical])		// syringe model
	precache_sound(fileNames[wav_drop])		// drop sound
	precache_sound(fileNames[wav_inject])		// inject sound
	
#if FULL_PRECACHE == 1 
	
	// DoD already precaches these???
	precache_sound(fileNames[wav_grunt])		// grunt sound
	precache_sound(fileNames[wav_inject2])		// inject sound 2
	
#endif
	
#if USE_SCIVOICES == 1

	precache_sound(sciVoices[sci_feel])		// sci feel voice
	precache_sound(sciVoices[sci_inject1])		// sci inject voice
	precache_sound(sciVoices[sci_inject2])		// sci inject voice

#endif
	
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Plugin Configuration (reads server gravity setting)
//
public plugin_cfg() 
{
	gravity_default = get_cvar_float("sv_gravity")
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Block fullupdate
//
public clcmd_fullupdate() 
{
	return PLUGIN_HANDLED	
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Player Spawn
//
public player_spawn(id)
{
	if(get_pcvar_num(p_meth) && is_user_alive(id) && is_user_connected(id))
		{
		if(meth_stamina[id])
			{
			dod_set_stamina(id, STAMINA_RESET)
			
			meth_stamina[id] = false
			
			if(task_exists(STAMINA_TASK+id))
				remove_task(STAMINA_TASK+id)
			}
			
		if(meth_gravity[id])
			{
			set_user_gravity(id,1.0)
			
			meth_gravity[id] = false
			
			if(task_exists(GRAVITY_TASK+id))
				remove_task(GRAVITY_TASK+id)
			}
			
		if(meth_visual[id])
			{
			meth_visual[id] = false
			
			if(task_exists(VISUAL_TASK+id))
				remove_task(VISUAL_TASK+id)
			
			if(task_exists(VISUALLOOP_TASK+id))
				remove_task(VISUALLOOP_TASK+id)
			}

			
		if(task_exists(EFFECT_TASK+id))
			remove_task(EFFECT_TASK+id)
			
		give_methamphetamine(id)
		}
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Give clients methamphetamine on spawn
//
public give_methamphetamine(id)
{
	new team = get_user_team(id)
	
	if(team == 1)
		{
		new brit = dod_get_map_info(MI_ALLIES_TEAM)
			
		if(brit == 0 && get_pcvar_num(p_allies))
			{
			switch(dod_get_user_class(id))
				{
				case DODC_GARAND: playerMethCount[id] = get_pcvar_num(p_garand)
				case DODC_CARBINE: playerMethCount[id] = get_pcvar_num(p_carbine)
				case DODC_THOMPSON: playerMethCount[id] = get_pcvar_num(p_thompson) 
				case DODC_GREASE: playerMethCount[id] = get_pcvar_num(p_grease) 
				case DODC_SNIPER: playerMethCount[id] = get_pcvar_num(p_sniper) 
				case DODC_BAR: playerMethCount[id] = get_pcvar_num(p_bar) 
				case DODC_30CAL: playerMethCount[id] = get_pcvar_num(p_30cal) 
				case DODC_BAZOOKA: playerMethCount[id] = get_pcvar_num(p_bazooka)
				}					
			}
		else if(brit == 1 && get_pcvar_num(p_brits))
			{
			switch(dod_get_user_class(id))
				{
				case DODC_ENFIELD: playerMethCount[id] = get_pcvar_num(p_enfield) 
				case DODC_STEN: playerMethCount[id] = get_pcvar_num(p_sten) 
				case DODC_MARKSMAN: playerMethCount[id] = get_pcvar_num(p_marksman) 
				case DODC_BREN: playerMethCount[id] = get_pcvar_num(p_bren) 
				case DODC_PIAT: playerMethCount[id] = get_pcvar_num(p_piat)
				}
			}			
		}
	else if(team == 2 && get_pcvar_num(p_axis))
		{
		switch(dod_get_user_class(id))
			{
			case DODC_KAR: playerMethCount[id] = get_pcvar_num(p_kar) 
			case DODC_K43: playerMethCount[id] = get_pcvar_num(p_k43) 
			case DODC_MP40: playerMethCount[id] = get_pcvar_num(p_mp40) 
			case DODC_MP44: playerMethCount[id] = get_pcvar_num(p_mp44) 
			case DODC_SCHARFSCHUTZE: playerMethCount[id] = get_pcvar_num(p_scopedk98) 
			case DODC_FG42: playerMethCount[id] = get_pcvar_num(p_fg42) 
			case DODC_SCOPED_FG42: playerMethCount[id] = get_pcvar_num(p_scopedfg42) 
			case DODC_MG34: playerMethCount[id] = get_pcvar_num(p_mg34) 
			case DODC_MG42: playerMethCount[id] = get_pcvar_num(p_mg42) 
			case DODC_PANZERJAGER: playerMethCount[id] = get_pcvar_num(p_panzer)
			}
		}
		
	if(get_pcvar_num(p_msg_spawn))
		client_print(id, print_chat, "* You have %d Methamphetamine %s...", playerMethCount[id], (playerMethCount[id] > 1) ? "syringes" : "syringe")

}

///////////////////////////////////////////////////////////////////////////////////////
//
// RoundState message
//
public round_message() 
{
	if(get_pcvar_num(p_meth))
		{
		new round_state = read_data(1)
	
		if(round_state == 3 || round_state == 4 || round_state == 5)
			{
			g_round_restart = true
			
			new needle_id = engfunc(EngFunc_FindEntityByString, -1, "classname", "methamphetamine_used")
			while((needle_id = engfunc(EngFunc_FindEntityByString, -1, "classname", "methamphetamine_used")) > 0)
				{
				if(needle_id && pev_valid(needle_id))
					{
					engfunc(EngFunc_RemoveEntity, needle_id)
					
					if(task_exists(NEEDLE_TASK+needle_id))
						remove_task(NEEDLE_TASK+needle_id)
					}
				}
				
			new id, iPlayer[32], iNumPlayers
			get_players(iPlayer,iNumPlayers)
			
			for(new i = 0; i < iNumPlayers; i++)
				{
				id = iPlayer[i]
				
				if(task_exists(EFFECT_TASK+id))
					remove_task(EFFECT_TASK+id)
					
				if(meth_stamina[id])
					{
					dod_set_stamina(id, STAMINA_RESET)
					
					meth_stamina[id] = false
					
					if(task_exists(STAMINA_TASK+id))
						remove_task(STAMINA_TASK+id)
					}
					
				if(meth_gravity[id])
					{
					set_user_gravity(id,1.0)
					
					meth_gravity[id] = false
					
					if(task_exists(GRAVITY_TASK+id))
						remove_task(GRAVITY_TASK+id)
					}
					
				if(meth_visual[id])
					{
					meth_visual[id] = false
					
					if(task_exists(VISUAL_TASK+id))
						remove_task(VISUAL_TASK+id)
						
					if(task_exists(VISUALLOOP_TASK+id))
						remove_task(VISUALLOOP_TASK+id)
					}
				}
			}		
		else
			g_round_restart = false
		}
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Client Death
//
public client_death(killer,victim,wpnindex,hitplace,TK)
{
	if(get_pcvar_num(p_meth) && is_user_connected(victim))
		{
		if(task_exists(EFFECT_TASK+victim))
			remove_task(EFFECT_TASK+victim)
			
		if(meth_stamina[victim])
			{
			dod_set_stamina(victim, STAMINA_RESET)
			
			if(task_exists(STAMINA_TASK+victim))
				remove_task(STAMINA_TASK+victim)
			
			meth_stamina[victim] = false
			}
						
		if(meth_gravity[victim])
			{
			set_user_gravity(victim,1.0)
			
			if(task_exists(GRAVITY_TASK+victim))
				remove_task(GRAVITY_TASK+victim)
			
			meth_gravity[victim] = false
			}
			
		if(meth_visual[victim])
			{	
			if(task_exists(VISUAL_TASK+victim))
				remove_task(VISUAL_TASK+victim)
				
			if(task_exists(VISUALLOOP_TASK+victim))
				remove_task(VISUALLOOP_TASK+victim)
			
			meth_visual[victim] = false
			}
		}
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Menu Functions
//
public meth_menu(id)
{
	if(get_pcvar_num(p_meth) && is_user_alive(id) && playerMethCount[id] && !g_round_restart)
		{	
		new message[1024]
		new len = format(message,1023,"Methamphetamine Menu^n^n")
		len += format(message[len],1023-len,"1. Inject yourself^n")
		len += format(message[len],1023-len,"2. inject another player^n^n")
		len += format(message[len],1023-len,"3. Count your syringes^n^n")
		len += format(message[len],1023-len,"0. Exit")
		show_menu(id,(1<<0)|(1<<1)|(1<<2)|(1<<9),message,-1,"methamphetamine_menu")
		}
		
	return PLUGIN_HANDLED
}

public menu_choice(id,key)
{
	if(get_pcvar_num(p_meth) && is_user_alive(id) && playerMethCount[id] && !g_round_restart)
		{	
		switch(key)
			{
			case 0: meth_self(id)
			case 1: meth_player(id)
			case 2: client_print(id, print_chat, "* You have %d Methamphetamine %s...", playerMethCount[id], (playerMethCount[id] != 1) ? "syringes" : "syringe")
			}
		}
		
	return PLUGIN_HANDLED
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Give yourself a methamphetamine shot
//
public meth_self(id)
{
	new Float:gametime = get_gametime()
	
	if(get_pcvar_num(p_meth) && is_user_alive(id) && get_pcvar_num(p_self) && playerMethCount[id] && !g_round_restart && gametime > g_nextInject[id])
		{
		client_cmd(id,"-attack;-reload;-speed;-forward;-back;-moveleft;-moveright")
				
		emit_sound(id, CHAN_ITEM, fileNames[wav_inject], 1.0, ATTN_NORM, 0, PITCH_NORM)
		
		emit_sound(id, CHAN_VOICE, fileNames[wav_inject2], 0.7, ATTN_NORM, 0, PITCH_NORM)
		
		new client[2]
		client[0] = id	//target
		client[1] = id	//who injected
		
		
		message_begin(MSG_ONE_UNRELIABLE,gMsgScreenShake,{0,0,0},id)
		write_short(1<<12) //ammount 
		write_short(2<<12) //lasts this long 
		write_short(140) //frequency
		message_end()
		
	
		set_task(get_pcvar_float(p_delay),"set_effect",EFFECT_TASK+id,client,2)
		
		
		drop_needle(id)
		
		new kills = dod_get_user_kills(id) + get_pcvar_num(p_kills_self)
		dod_set_user_kills(id,kills,0)
		
		message_begin(MSG_BROADCAST, gMsgFrags, {0,0,0}, 0)
		write_byte(id)
		write_short(kills)
		message_end()
					
		new steam[32],teamname[32],name[32]
		new userid = get_user_userid(id)
		get_user_authid(id, steam, 31)
		dod_get_pl_teamname(id, teamname, 31)
		get_user_name(id, name, 31)
		
		log_message("^"%s<%d><%s><%s>^" triggered ^"weaponstats^" (weapon ^"methamphetamine^") (shots ^"1^") (hits ^"1^") (kills ^"0^") (headshots ^"0^") (tks ^"0^") (damage ^"0^") (deaths ^"0^") (score ^"0^")",name,userid,steam,teamname)		
		log_message("^"%s<%d><%s><%s>^" triggered ^"weaponstats2^" (weapon ^"methamphetamine^") (head ^"0^") (chest ^"0^") (stomach ^"0^") (leftarm ^"1^") (rightarm ^"0^") (leftleg ^"0^") (rightleg ^"0^")",name,userid,steam,teamname)
		
		client_print(id,print_chat,"* You have injected yourself with a shot of methamphetamine *")
		
		playerMethCount[id]--
		g_nextInject[id] = (gametime + get_pcvar_float(p_delayinject))
		
		if(get_pcvar_num(p_msg_use))
			client_print(id, print_chat, "* You have %d Methamphetamine %s left...", playerMethCount[id], (playerMethCount[id] != 1) ? "syringes" : "syringe")
		}
	
	return PLUGIN_HANDLED
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Give another player a methamphetamine shot
//
public meth_player(id)
{
	new Float:gametime = get_gametime()
	
	if(get_pcvar_num(p_meth) && is_user_alive(id) && get_pcvar_num(p_others) && playerMethCount[id] && !g_round_restart && gametime > g_nextInject[id])
		{
		new ent,bodypart
		get_user_aiming(id,ent,bodypart)
		if(ent && pev_valid(ent) && ent>0 && ent<33)
			{
			new classname[32]
			pev(ent,pev_classname, classname, 31)
			if(equali(classname,"player") && is_user_alive(ent))
				{	
				new Float:plr_origin[3], Float:ent_origin[3]
				pev(id, pev_origin, plr_origin)
				pev(ent, pev_origin, ent_origin)
							
				new Float:distance = get_distance_f(plr_origin, ent_origin)
				
				new ent_name[32]
				get_user_name(ent,ent_name,31)
							
				if(distance < 60.0)
					{
							
#if USE_SCIVOICES == 1
						
					if(random_num(0,1) == 1)
						emit_sound(id, CHAN_VOICE, sciVoices[sci_inject1], 0.6, ATTN_NORM, 0, PITCH_NORM)
					else
						emit_sound(id, CHAN_VOICE, sciVoices[sci_inject2], 0.6, ATTN_NORM, 0, PITCH_NORM)
					
#endif
					
					client_cmd(id,"-attack;-reload;-speed;-forward;-back;-moveleft;-moveright")
					client_cmd(ent,"-attack;-attack2;-reload;-speed;-forward;-back;-moveleft;-moveright")
					
					emit_sound(id, CHAN_ITEM, fileNames[wav_inject], 1.0, ATTN_NORM, 0, PITCH_NORM)
					
					emit_sound(ent, CHAN_VOICE, fileNames[wav_inject2], 0.7, ATTN_NORM, 0, PITCH_NORM)
					
					new client[2]
					client[0] = ent		//target
					client[1] = id		//who injected
					
					message_begin(MSG_ONE_UNRELIABLE,gMsgScreenShake,{0,0,0},ent)
					write_short(1<<12) //ammount 
					write_short(2<<12) //lasts this long 
					write_short(140) //frequency
					message_end()	
					
					set_task(get_pcvar_float(p_delay),"set_effect", EFFECT_TASK+ent, client, 2)
			
					drop_needle(id)
					
					new plr_team = get_user_team(id)
					new ent_team = get_user_team(ent)
					
					new plr_name[32]
					get_user_name(id,plr_name,31)

					new  bodyplace[12]
					new bp_head = 0,bp_chest = 0,bp_stomach = 0,bp_leftarm = 0,bp_rightarm = 0,bp_leftleg = 0,bp_rightleg = 0

					switch(bodypart)
						{
						case 1: { bp_head = 1;  bodyplace = "head"; }
						case 2:{  bp_chest = 1;  bodyplace = "chest"; }
						case 3: { bp_stomach = 1;  bodyplace = "stomach"; }
						case 4: { bp_leftarm = 1;  bodyplace = "left arm"; }
						case 5: { bp_rightarm = 1;  bodyplace = "right arm"; }
						case 6: { bp_leftleg = 1;  bodyplace = "left leg"; }
						case 7: { bp_rightleg = 1;  bodyplace = "right leg"; }
						}
					
					new steam[32],teamname[32],name[32]
					new userid = get_user_userid(id)
					get_user_authid(id, steam, 31)
					dod_get_pl_teamname(id, teamname, 31)
					get_user_name(id, name, 31)
					
					if(plr_team == ent_team)
						{
						new kills = dod_get_user_kills(id) + get_pcvar_num(p_kills_team)
						dod_set_user_kills(id,kills,0)
						
						message_begin(MSG_BROADCAST, gMsgFrags, {0,0,0}, 0)
						write_byte(id)
						write_short(kills)
						message_end()
						
						client_print(id,print_chat,"* You have injected methamphetamine into the %s of %s *",bodyplace,ent_name)
						client_print(ent,print_chat,"* %s has injected your %s with a shot of methamphetamine *",plr_name,bodyplace)
						}
					else
						{
						new kills = dod_get_user_kills(id) + get_pcvar_num(p_kills_enemy)
						dod_set_user_kills(id,kills,0)
						
						message_begin(MSG_BROADCAST, gMsgFrags, {0,0,0}, 0)
						write_byte(id)
						write_short(kills)
						message_end()
						
						client_print(id,print_chat,"* You have injected methamphetamine into the %s of %s, you're giving aid to the enemy! *",bodyplace,ent_name)
						client_print(ent,print_chat,"* %s has injected your %s with a shot of methamphetamine, the enemy is helping you! *",plr_name,bodyplace)
						}
					
					log_message("^"%s<%d><%s><%s>^" triggered ^"weaponstats^" (weapon ^"methamphetamine^") (shots ^"1^") (hits ^"1^") (kills ^"1^") (headshots ^"%d^") (tks ^"0^") (damage ^"0^") (deaths ^"0^") (score ^"0^")",name,userid,steam,teamname,bp_head)		
					log_message("^"%s<%d><%s><%s>^" triggered ^"weaponstats2^" (weapon ^"methamphetamine^") (head ^"%d^") (chest ^"%d^") (stomach ^"%d^") (leftarm ^"%d^") (rightarm ^"%d^") (leftleg ^"%d^") (rightleg ^"%d^")",name,userid,steam,teamname,bp_head,bp_chest,bp_stomach,bp_leftarm,bp_rightarm,bp_leftleg,bp_rightleg)
											
					playerMethCount[id]--
					g_nextInject[id] = (gametime + get_pcvar_float(p_delayinject))
						
					if(get_pcvar_num(p_msg_use))
						client_print(id, print_chat, "* You have %d Methamphetamine %s left...", playerMethCount[id], (playerMethCount[id] != 1) ? "syringes" : "syringe")
					}
				else
					client_print(id,print_chat,"* %s is too far away to give a methamphetamine injection *",ent_name)
				}
			}
		else
			client_print(id,print_chat,"* You are not aiming at a player! No one to give a methamphetamine injection *")
		}
		
	return PLUGIN_HANDLED
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Start the methamphetamine effects
//
public set_effect(client[])
{
	new target = client[0]
	new id = client[1]
	
	if(is_user_alive(target) && is_user_connected(target) && !g_round_restart)
		{
		new is_bot = is_user_bot(target)
		
#if USE_SCIVOICES == 1
		
		emit_sound(target, CHAN_VOICE, sciVoices[sci_feel], 0.8, ATTN_NORM, 0, PITCH_NORM)
		
#endif

#if SUBTRACT_HP == 0

		// health effect (addition)
		if(get_pcvar_num(p_health))
			{
			new player_health = get_user_health(target)
			new max_health = get_pcvar_num(p_health_max)
			new health_amt = get_pcvar_num(p_health_amt)
			
			new health_total = player_health + health_amt
								
			if(health_total > max_health)
				health_amt -= (health_total - max_health)
				
			set_user_health(target, player_health + health_amt)
			
			if(is_user_connected(id))
				{
				new steam[32],teamname[32],name[32]
				new userid = get_user_userid(id)
				get_user_authid(id, steam, 31)
				dod_get_pl_teamname(id, teamname, 31)
				get_user_name(id, name, 31)
					
				log_message("^"%s<%d><%s><%s>^" triggered ^"weaponstats^" (weapon ^"methamphetamine^") (shots ^"0^") (hits ^"0^") (kills ^"0^") (headshots ^"0^") (tks ^"0^") (damage ^"%d^") (deaths ^"0^") (score ^"0^")",name,userid,steam,teamname,health_amt)
				}
			}
			
#else

		// health effect (subtraction)
		if(get_pcvar_num(p_health))
			{
			new player_health = get_user_health(target)
			new health_amt = get_pcvar_num(p_health_amt)
			
			new health_total = player_health - health_amt
			
			if(health_total < 1)
				health_amt -= (health_amt - player_health + 1)
				
			set_user_health(target, player_health - health_amt)

			if(is_user_connected(id))
				{
				new steam[32],teamname[32],name[32]
				new userid = get_user_userid(id)
				get_user_authid(id, steam, 31)
				dod_get_pl_teamname(id, teamname, 31)
				get_user_name(id, name, 31)
					
				log_message("^"%s<%d><%s><%s>^" triggered ^"weaponstats^" (weapon ^"methamphetamine^") (shots ^"0^") (hits ^"0^") (kills ^"0^") (headshots ^"0^") (tks ^"0^") (damage ^"%d^") (deaths ^"0^") (score ^"0^")",name,userid,steam,teamname,health_amt)
				}
			}
		
#endif
		
		// stamina effect		
		if(get_pcvar_num(p_stamina) && !is_bot)
			{
			if(meth_stamina[target])
				if(task_exists(STAMINA_TASK+target))
					remove_task(STAMINA_TASK+target)
		
			dod_set_stamina(target, STAMINA_SET, 100, 100)
			meth_stamina[target] = true
		
			set_task(get_pcvar_float(p_stamina_time),"reset_stamina", STAMINA_TASK+target, client, 1)
			}
		// gravity effect
		if(get_pcvar_num(p_gravity))
			{
			if(meth_gravity[target])
				if(task_exists(GRAVITY_TASK+target))
					remove_task(GRAVITY_TASK+target)
				
			new gravity_cvar = get_pcvar_num(p_gravity_amt)
			
			new Float:gravity_user = (((get_user_gravity(target) * gravity_default) - gravity_cvar) / gravity_default)
						
			set_user_gravity(target,gravity_user)
			meth_gravity[target] = true
		
			set_task(get_pcvar_float(p_gravity_time),"reset_gravity", GRAVITY_TASK+target, client, 1)
			}	
		// visual effect
		if(get_pcvar_num(p_visual) && !is_bot)
			{
			if(meth_visual[target])
				{
				if(task_exists(VISUAL_TASK+target))
					remove_task(VISUAL_TASK+target)
				}
			else
				meth_visual[target] = true
			
			set_task(0.3, "visual_effect", VISUALLOOP_TASK+target, client, 1, "b")
			set_task(get_pcvar_float(p_visual_time), "remove_visual", VISUAL_TASK+target, client, 1)
			}
			
	/*	message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},target)
		write_byte(110)
		message_end()
		
		set_task(15.0, "reset_fov", VISUAL_TASK+target, client, 1)
	*/
	
		message_begin(MSG_ONE_UNRELIABLE,gMsgScreenFade,{0,0,0},target)
		write_short(1<<12)  //duraiton
		write_short(1<<10)  //hold time
		write_short(0)  //flags
		write_byte(255) //red
		write_byte(255) //green
		write_byte(255) //blue
		write_byte(180) //alpha
		message_end()
			
		emit_sound(target, CHAN_BODY, fileNames[wav_grunt], 1.0, ATTN_NORM, 0, PITCH_NORM)
		}	
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Visual Effects
//
public visual_effect(client[])
{
	new id = client[0]
	
	if(is_user_alive(id) && is_user_connected(id))
		{		
		new Origin[3],Num
		FindEmptyLoc(id,Origin,Num)
					
		switch(random_num(0,5))
			{
			case 0: {			
				message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
				write_byte(TE_SPARKS)
				write_coord(Origin[0])
				write_coord(Origin[1])
				write_coord(Origin[2])
				message_end()
				}
			case 1: {
				message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
				write_byte(TE_DLIGHT)
				write_coord(Origin[0])
				write_coord(Origin[1])
				write_coord(Origin[2])
				write_byte(random_num(5,50)) //(radius in 10's) 
				write_byte(random_num(0,255)) // red
				write_byte(random_num(0,255)) // green
				write_byte(random_num(0,255)) // blue
				write_byte(random_num(10,40)) //(life in 10's) 
				write_byte(random_num(5,20)) //(decay rate in 10's) 
				message_end()
				}
			case 2: {
				message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
				write_byte(TE_IMPLOSION)
				write_coord(Origin[0])
				write_coord(Origin[1])
				write_coord(Origin[2])
				write_byte(3000)//random_num(500,1000))	//radius
				write_byte(random_num(150,250))		//count
				write_byte(random_num(10,40))		//life in 0.1's
				message_end()
				}
			case 3: {
				message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
				write_byte(TE_SPARKS)
				write_coord(Origin[0])
				write_coord(Origin[1])
				write_coord(Origin[2])
				message_end()
				}
		//	case 4: {
		//		message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
		//		write_byte(TE_LAVASPLASH)
		//		write_coord(Origin[0])
		//		write_coord(Origin[1])
		//		write_coord(Origin[2])
		//		message_end()
		//		}
			case 4: {
				message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
				write_byte(TE_DLIGHT)
				write_coord(Origin[0])
				write_coord(Origin[1])
				write_coord(Origin[2])
				write_byte(random_num(10,25)) //(radius in 10's) 
				write_byte(random_num(0,255)) // red
				write_byte(random_num(0,255)) // green
				write_byte(random_num(0,255)) // blue
				write_byte(random_num(5,20)) //(life in 10's) 
				write_byte(random_num(5,10)) //(decay rate in 10's) 
				message_end()
				}
			case 5: {
				message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,Origin,id)
				write_byte(TE_SPARKS)
				write_coord(Origin[0])
				write_coord(Origin[1])
				write_coord(Origin[2])
				message_end()
				}
			}
		}
}	

///////////////////////////////////////////////////////////////////////////////////////
//
// Drop the needle on the ground..
//
public drop_needle(id)
{
	new needle_id = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	if(!needle_id || !pev_valid(needle_id))
		return PLUGIN_HANDLED

	new Float:PlayerOrigin[3]
	
	pev(id, pev_origin, PlayerOrigin)
	PlayerOrigin[2] += 10

	set_pev(needle_id, pev_classname, "methamphetamine_used")	
	set_pev(needle_id, pev_origin, PlayerOrigin)
	engfunc(EngFunc_SetModel, needle_id, fileNames[mdl_medical])
	set_pev(needle_id, pev_movetype, MOVETYPE_TOSS)		
	set_pev(needle_id, pev_solid, SOLID_BBOX)	
	set_pev(needle_id, pev_owner, id)	

	set_pev(needle_id, pev_body, 6)
	set_pev(needle_id, pev_friction, 0.3)	
	set_pev(needle_id, pev_gravity, 0.5)
	
	emit_sound(needle_id, CHAN_BODY, fileNames[wav_drop], 0.6, ATTN_NORM, 0, PITCH_NORM)
	
	new needle_used[1]
	needle_used[0] = needle_id
	
	set_task(8.0,"remove_needle", NEEDLE_TASK+needle_id, needle_used, 1)
		
	return PLUGIN_HANDLED
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Remove the needle entity off the ground
//
public remove_needle(needle_used[])
{
	if(pev_valid(needle_used[0]))
		engfunc(EngFunc_RemoveEntity, needle_used[0])
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Stop visual effects
//
public remove_visual(client[])
{
	new id = client[0]
	
	if(is_user_connected(id))
		{
		if(task_exists(VISUAL_TASK+id))
			remove_task(VISUAL_TASK+id)
			
		if(task_exists(VISUALLOOP_TASK+id))
			remove_task(VISUALLOOP_TASK+id)
		
		meth_visual[id] = false
		}
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Reset a client's stamina to normal
//
public reset_stamina(client[])
{
	new id = client[0]
	
	if(is_user_connected(id))
		{
		dod_set_stamina(id, STAMINA_RESET)
		
		meth_stamina[id] = false
		}
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Reset a client's gravity to normal
//
public reset_gravity(client[])
{
	new id = client[0]
	
	if(is_user_connected(id))
		{
		set_user_gravity(id,1.0)
		
		meth_gravity[id] = false
		}
}

/*
///////////////////////////////////////////////////////////////////////////////////////
//
// Reset a client's fov to normal
//
public reset_fov(client[])
{
	new id = client[0]
	
	if(is_user_connected(id))
		{
		message_begin(MSG_ONE_UNRELIABLE,gMsgSetFOV,{0,0,0},id)
		write_byte(90)
		message_end()
		
		message_begin(MSG_ONE_UNRELIABLE,gMsgScreenFade,{0,0,0},id)
		write_short(1<<10)  //duraiton
		write_short(1<<10)  //hold time
		write_short(0x0002)  //flags
		write_byte(100) //red
		write_byte(0) //green
		write_byte(0) //blue
		write_byte(160) //alpha
		message_end()
			
		message_begin(MSG_ONE_UNRELIABLE,get_user_msgid("ScreenShake"),{0,0,0},id)
		write_short(1<<12) //ammount 
		write_short(2<<12) //lasts this long 
		write_short(160) //frequency
		message_end()
		
		//meth_gravity[id] = false
		}
}
*/

///////////////////////////////////////////////////////////////////////////////////////
//
// Used to find origins for visual effect (from Hawk552's drugmod)
//
FindEmptyLoc(id,Origin[3],&Num)
{
	if(Num++ > 50)
		return 0
	
	new Float:pOrigin[3]
	pev(id,pev_origin,pOrigin)
	
	for(new Count;Count < 2;Count++)
		pOrigin[Count] += random_float(-700.0,700.0)
	
	if(engfunc(EngFunc_PointContents,pOrigin) != CONTENTS_EMPTY && engfunc(EngFunc_PointContents,pOrigin) != CONTENTS_SKY)
		return FindEmptyLoc(id,Origin,Num)
	
	Origin[0] = floatround(pOrigin[0])
	Origin[1] = floatround(pOrigin[1])
	Origin[2] = floatround(pOrigin[2])
	
	return PLUGIN_HANDLED
}

#if DEBUG_MODE == 1

///////////////////////////////////////////////////////////////////////////////////////
//
// Debug Command
//
public debug_givemeth(id,level,cid)
{
	if(cmd_access(id, level, cid, 1))
		playerMethCount[id] += 5
		
	return PLUGIN_HANDLED
}

#endif
